public class JavaGlue extends Module {
public Stack<Choicepoint> tryToContinue(Compound term, int choice, Stack<Choicepoint> choicepoints, Unifier unifier) {
int nextHeight = choicepoints.height+1;
Stack<Conjunct> query = choicepoints.head.query.tail;
if(term.arity == 1 && term.name.equals("write_character")) {
if(choice == 1) {
final Term t2 = new Variable();
final Term t1 = new Compound("write_character", t2);
if(unifier.unify(term,t1)) {
status = Module.Status.Success;
query = new Stack<Conjunct>(new JavaCall() { public boolean call() {
try {
System.out.print(t2.coerceToChar());
return true;
} catch(Exception e) { return false; }
}},query);
return new Stack<Choicepoint>(new Choicepoint(query,unifier.bound,false),choicepoints);
}
else {
status = Module.Status.TryAgain;
return choicepoints;
}
}
status = Module.Status.ThatsAll;
return choicepoints;
}
if(term.arity == 1 && term.name.equals("write_string")) {
if(choice == 1) {
final Term t2 = new Variable();
final Term t1 = new Compound("write_string", t2);
if(unifier.unify(term,t1)) {
status = Module.Status.Success;
query = new Stack<Conjunct>(new JavaCall() { public boolean call() {
try {
System.out.print(t2.coerceToString());
return true;
} catch(Exception e) { return false; }
}},query);
return new Stack<Choicepoint>(new Choicepoint(query,unifier.bound,false),choicepoints);
}
else {
status = Module.Status.TryAgain;
return choicepoints;
}
}
status = Module.Status.ThatsAll;
return choicepoints;
}
if(term.arity == 1 && term.name.equals("xx")) {
if(choice == 1) {
final Term t3 = new Compound("102");
final Term t5 = new Compound("111");
final Term t7 = new Compound("111");
final Term t8 = new Compound("[]");
final Term t6 = new Compound(".", t7, t8);
final Term t4 = new Compound(".", t5, t6);
final Term t2 = new Compound(".", t3, t4);
final Term t1 = new Compound("xx", t2);
if(unifier.unify(term,t1)) {
status = Module.Status.Success;
return new Stack<Choicepoint>(new Choicepoint(query,unifier.bound,false),choicepoints);
}
else {
status = Module.Status.TryAgain;
return choicepoints;
}
}
else if(choice == 2) {
final Term t3 = new Compound("98");
final Term t5 = new Compound("97");
final Term t7 = new Compound("114");
final Term t8 = new Compound("[]");
final Term t6 = new Compound(".", t7, t8);
final Term t4 = new Compound(".", t5, t6);
final Term t2 = new Compound(".", t3, t4);
final Term t1 = new Compound("xx", t2);
if(unifier.unify(term,t1)) {
status = Module.Status.Success;
return new Stack<Choicepoint>(new Choicepoint(query,unifier.bound,false),choicepoints);
}
else {
status = Module.Status.TryAgain;
return choicepoints;
}
}
status = Module.Status.ThatsAll;
return choicepoints;
}
if(term.arity == 0 && term.name.equals("example")) {
if(choice == 1) {
final Term t1 = new Compound("example");
if(unifier.unify(term,t1)) {
status = Module.Status.Success;
final Term t3 = new Variable();
final Term t2 = new Compound("write_string", t3);
query = new Stack<Conjunct>(new Predicate(t2,0,nextHeight),query);
final Term t4 = new Compound("xx", t3);
query = new Stack<Conjunct>(new Predicate(t4,0,nextHeight),query);
final Term t7 = new Compound("70");
final Term t9 = new Compound("111");
final Term t11 = new Compound("111");
final Term t13 = new Compound("111");
final Term t15 = new Compound("111");
final Term t17 = new Compound("111");
final Term t19 = new Compound("111");
final Term t21 = new Compound("111");
final Term t23 = new Compound("111");
final Term t24 = new Compound("[]");
final Term t22 = new Compound(".", t23, t24);
final Term t20 = new Compound(".", t21, t22);
final Term t18 = new Compound(".", t19, t20);
final Term t16 = new Compound(".", t17, t18);
final Term t14 = new Compound(".", t15, t16);
final Term t12 = new Compound(".", t13, t14);
final Term t10 = new Compound(".", t11, t12);
final Term t8 = new Compound(".", t9, t10);
final Term t6 = new Compound(".", t7, t8);
final Term t5 = new Compound("write_string", t6);
query = new Stack<Conjunct>(new Predicate(t5,0,nextHeight),query);
return new Stack<Choicepoint>(new Choicepoint(query,unifier.bound,false),choicepoints);
}
else {
status = Module.Status.TryAgain;
return choicepoints;
}
}
status = Module.Status.ThatsAll;
return choicepoints;
}
status = Module.Status.NotFound;
return choicepoints;
}
}
